from google.appengine.api import users
from google.appengine.ext import db
from widget import Widget

import jinja2
import json
import os
import os.path
import webapp2

jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

class MainPage(webapp2.RequestHandler):
    def get(self):
			usr = users.get_current_user()
			if usr:
				usr_name = usr.nickname()
				usr_key = usr.user_id()
				auth_url = users.create_logout_url(self.request.uri)
				auth_txt = 'Logout'
			else:
				usr_name = "Guest"
				usr_key = ""
				auth_url = users.create_login_url(self.request.uri)
				auth_txt = 'Login'

			template_values = {
												'usr_name':usr_name,
												'usr_key' : usr_key,
												'auth_url':auth_url,
												'auth_txt':auth_txt				
												}
			
			template = jinja_environment.get_template('view/index.html')
			self.response.out.write(template.render(template_values))
			

app = webapp2.WSGIApplication([('/', MainPage),
															('/widget', Widget)], debug=True)

